var _server = "http://localhost:8085";
moviePicSr="../../static/Images/Movie";
comicPicSr="../../static/Images/Comic";
userPicSr="../../static/Images/User";
tvShowPicSr="../../static/Images/TvShow";
var type;
var mame;
$(function () {
});
var sortPageTotal;
var searchPageTotal;
$("#sort").on("click","a",function () {
    searchPageTotal=0;
    type=($(this).attr("id"));
    $("#Home").hide();
    $("#SortHome").removeClass("hidden");
    initSortPageTotal(type);
    writesortContentList(1,type);
    $("#sortPageList li:eq(1)").addClass("active").siblings().removeClass("active");
});
$("#sortPageList").on("click","li:not(:first,:last)",function () {
    var currentPage=parseInt($(this).find('a').html());
    if (searchPageTotal==0) {
        writePageList(currentPage, sortPageTotal, currentPage, "sortPageList");
        writesortContentList(currentPage, type);
    }else {
        writePageList(currentPage, searchPageTotal, currentPage, "sortPageList");
        writesearchContentList(currentPage, name);
    }
});
$("#sortPageList").on("click","li:eq(0)",function () {
    if (searchPageTotal==0) {
        writePageList(1,sortPageTotal,1,"sortPageList");
        writesortContentList(1,type);
    }else {
        writePageList(1, searchPageTotal, 1, "sortPageList");
        writesearchContentList(1, name);
    }
});
$("#sortPageList").on("click","li:last",function () {
    if (searchPageTotal==0) {
        writePageList(sortPageTotal,sortPageTotal,sortPageTotal,"sortPageList");
        writesortContentList((sortPageTotal),type);
    }else {
        writePageList(searchPageTotal, searchPageTotal, searchPageTotal, "sortPageList");
        writesearchContentList(searchPageTotal, name);
    }
});
$("#searchbutton").on("click",function () {
    sortPageTotal=0;
    name=($("#searchName").val());
    if(name==""){
        $('#searchName').attr("placeholder", "搜索内容不能为空 ！");
        return false;
    }
    $("#Home").hide();
    $("#SortHome").removeClass("hidden");
    initSearchPageTotal(name);
    writesearchContentList(1,name);
    $("#sortPageList li:eq(1)").addClass("active").siblings().removeClass("active");
});

function writesortContentList(currentPage,type) {
    $.ajax({
        url: _server + "/bssp/main/sortList",
        type: 'post',
        dataType: 'json',
        data: {"currentPage":currentPage,"anyNum":type},
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (result) {
            writeContent(result.data,"sortContentList");
        },
        error: function (result) {
            layer.msg("首页请求失败",{time:1500});
        }
    });
}
function initSortPageTotal(type) {
    $.ajax({
        url: _server + "/bssp/main/sortPage",
        type: 'post',
        dataType: 'json',
        data: {type:type},
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (result) {
            sortPageTotal=Math.ceil((result.data.sortPageTotal)/20);
            writePageList(1,sortPageTotal,1,"sortPageList");
        },
        error: function (result) {
            layer.msg("首页请求失败",{time:1500});
        }
    });
}
function initSearchPageTotal(name) {
    $.ajax({
        url: _server + "/bssp/main/searchCount",
        type: 'post',
        dataType: 'json',
        data: {name:name},
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (result) {
            searchPageTotal=Math.ceil((result.data)/20);
            writePageList(1,searchPageTotal,1,"sortPageList");
        },
        error: function (result) {
            layer.msg("首页请求失败",{time:1500});
        }
    });
}
function writesearchContentList(currentPage,name) {
    $.ajax({
        url: _server + "/bssp/main/search",
        type: 'post',
        dataType: 'json',
        data: {"currentPage":currentPage,"anyName":name},
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (result) {
            writeContent(result.data,"sortContentList");
        },
        error: function (result) {
            layer.msg("首页请求失败",{time:1500});
        }
    });
}